﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using System.Collections.Generic;

public partial class UserControl_ProductsByCategory : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
            //nếu có QueryString
            if (Request.QueryString["CateID"] != null)
            {
                int id = Int32.Parse(Request.QueryString["CateID"]);
               
                string nameCate = LoaiSanPhamBUS.GetNameByID(id) == null ? "Chưa có Loại sản phẩm này" : LoaiSanPhamBUS.GetNameByID(id).ToUpper();

                lblCatePro.InnerHtml = nameCate;

                Page.Title = Page.Title + " " + nameCate;
                ViewState["cateid"] = id;
            }            

        }
    }
    protected void DataPager1_PreRender(object sender, EventArgs e)
    {
        List<SanPhamBUS> list = SanPhamBUS.GetAll();
        if (ViewState["cateid"] != null)
        {
            int id = (int)ViewState["cateid"];
            list = SanPhamBUS.GetByLoaiSanPham(id);
        }
        lvProducts.DataSource = list;
        lvProducts.DataBind();
    }
}
